<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$hmid=$_RQ['id'];
	if(!$hmid){
			$hmid=$_SESSION['hmid'];
		}else{
			$_SESSION['hmid']=$hmid;
		}
	$huoma=pdo_get('jy_huoma_list',array('id'=>$hmid));	
if($huoma['type']==1){
		$title='二维码';
		$str='image';
		$help='';
	}else{
		$title='链接';
		$str='string';
		$help='必须为带http头的完整地址';
	}	
	//print_r($huoma);exit();
if($_RQ['op']=='list'){
	
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'hmid'=>$hmid);
    $fields=array('id','content','createtime','remark');
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_huoma_content',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	foreach($return['list'] as &$v){
		
		$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
	}
	
	
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'内容管理'),
			array('op'=>'edit','title'=>'添加内容'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'content','title'=>$title,'type'=>$str),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),			
			 
		),
		
		),
	
	);
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='edit'){
	
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_huoma_content',array('id'=>$id));
	}else{
		$item=array();
	}
    $return['item']=$item;
	$return['status']=array('0'=>'关闭','1'=>'活动进行中');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'活码设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'内容管理'),
			array('op'=>'edit','title'=>'添加内容')
		),
		'edit'=>array(
			array('name'=>'content','title'=>$title,'type'=>$str,'help'=>$help),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			)
			);
	$return['htmls']=$htmls;
	exi($return);
	}
	if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('content','remark'),$postdata);
	$data['createtime']=TIMESTAMP;
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_huoma_content',$data,array('id'=>$id));
				exi('设置成功！','','list');
			}else{
			    $data['uniacid']=$_SESSION['uniacid'];
				$data['hmid']=$hmid;					
				pdo_insert('jy_huoma_content',$data);
				exi('添加成功！','','list');
			}
			}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_huoma_content',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_huoma_content',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>